import React from 'react';
import {
  Form,
  Input,
  Button,
  Table,
  Icon,
  Radio,
  InputNumber,
  Checkbox,
  Modal,
  message,
  notification,
  Affix,
  Upload,
  Select
} from 'antd';

import InnerTable from 'components/DBTable/InnerTable.js';
import ajax from '../../../utils/ajax';

const FormItem = Form.Item;
const ButtonGroup = Button.Group;
const Option = Select.Option;

var _this;

/**
 * 内部表格组件
 */
class ClientVersionInnerTable extends InnerTable {


  /**
   * 构造器，好像是用来初始化的？
   * @param props
   */
  constructor(props) {
    super(props);
  }


  /**
   * 这里好像是用来配置那些按钮之类的
   * @returns {Array}
   */
  prepareToolBar = function () {

    //上面是选择框的那个配置
    var items = [];

    // items.push(<Button key='audioUpBtn' type="primary"  onClick={this.onClickUpLoadPicture}>
    //   <Icon type="edit"/>上传图片
    // </Button>);

    return items;
  }


  // onClickUpLoadPicture = () =>{
  //   delete this.state.fileList; //删除上传框那里的文件
  //   //框可见
  //   this.setState({modalVisible: true, fileList:[], modalState: this.modalActionState.Insert});
  // }

  onImageFileChange = (info) =>{
    let fileList = info.fileList;

    if (fileList.length > 1) {
      fileList = fileList.slice(-1); //最多只能有一个文件
    }

    if (info.file.response) {
      fileList = fileList.map((file) => {
        file.url = file.response.data.url;
        return file;
      });
      let id = info.file.response.data.id;
      this.props.form.setFieldsValue({imageId: id});

      let data = info.file.response.data;

      //设置别的值
      this.props.form.setFieldsValue({height:data.height});
      this.props.form.setFieldsValue({id:data.id});
      this.props.form.setFieldsValue({imgUrl:data.url});
      this.props.form.setFieldsValue({key:data.key});
      this.props.form.setFieldsValue({size:data.size});
      this.props.form.setFieldsValue({width:data.width});
      this.props.form.setFieldsValue({suffix:data.suffix});
      this.props.form.setFieldsValue({imageAve:data.imageAve});

      let doSave =  this.props.form.getFieldValue('doSave');
      if(doSave == 1){
        data = this.props.form.getFieldsValue();
        if(data){
          data =  JSON.stringify(data);
          _this = this;
          ajax.post({
            url:"/imagemanage/saveImage",
            params:{imageStr:data},
            success:function(res){
              if(res.errorCode==200){
                console.log("保存到数据库成功~~id 是", res.data.id );
                _this.props.form.setFieldsValue({id:res.data.id});
              }
            }
          })
        }
      }

    }

    this.setState({fileList: fileList});
  }

  //点击确定，新增之前处理数据，这里因为不需要添加，所以直接进行return null;
  // handleData = (data) =>{
  //   this.setState({ modalVisible: false });
  // }

}

export default ClientVersionInnerTable;
